/**
 * 功能描述
 */

define(function(require, exports, module) {
	var Grid = require("grid");
	var fetchProperties = require("../constant/fetchProperties");
	var moment = require("moment");
	var gridEvents = require("../handler/gridEvents");
	var instance = {
		initComponent : function(params, widget) {
			var grid = new Grid({
				parentNode : ".J-grid",
				autoRender: false,
				model : {
					url:"api/alliancesettlement/querysetl",
					params : function() {
						var subnav = widget.get("subnav");
						var servicePoint = subnav.getValue("servicePoint");
						var destination = subnav.getValue("destination");
						var checkInDate = subnav.getValue("travelDate").start;
						var checkInDateEnd = subnav.getValue("travelDate").end;
						
						return {
							"planItemGroup.servicePoint":servicePoint,
							"planItemGroup.planItem.destination":destination,
							"checkInDate":checkInDate,
							"checkInDateEnd":checkInDateEnd,
							"planItemGroup.alliance":"false",
							"planItemGroup.checkInStatus":"CheckIn",
							"checkInType":"Alliance",
							"fetchProperties":fetchProperties.grid
						};
					},
					columns : [ {
						name : "allianceConfirm.groupReserve.planItemGroup.planItem.startDate",
						label : "年度",
						format :"date",
						formatparams:{
							mode:"YYYY"
						}
					}, {
						name : "allianceConfirm.groupReserve.planItemGroup.planItem.destination.name",
						label : "目的地"
					}, {
						name : "allianceConfirm.groupReserve.checkInDate",
						label : "入住日期",
						format :"date",
						formatparams:{
							mode:"YYYY-MM-DD"
						}
					}, {
						name : "allianceConfirm.groupReserve.checkOutDate",
						label : "退房日期",
						format :"date",
						formatparams:{
							mode:"YYYY-MM-DD"
						}
					}, {
						name : "signUpNumber",
						label : "报名人数"
					}, {
						name : "allianceConfirm.groupReserve.planItemGroup.servicePoint.name",
						label : "组团单位"
					}, {
						name : "allianceSettlement",
						label : "状态",
						format: function(value, data) {
							if(value){
								if(value.settlementDate){
									return "已结算";
								}else{
									return "待结算";
								}
							}else{
								return "待结算";
							}
			            }
					}, {
						name : "allianceSettlement",
						label : "结算日期",
						format: function(value, data) {
							if(value && value.settlementDate){
								return moment(value.settlementDate).format("YYYY-MM-DD");
							}else{
								return "";								
							}
			            }
					}, {
						name : "allianceSettlement",
						label : "操作",
						format:"button",
						formatparams:[{
							id:"billing",
							text:"结算",
							show:function(value,row){
								if(value){
									if(value.settlementDate){
										return false;
									}else{
										return true;
									}
								}else{
									return true;
								}
							},
							handler:function(index,data,rowEle){
								gridEvents.billing(data,widget);
							}
						},{
							id:"confirm",
							text:"查看",
							handler:function(index,data,rowEle){
								gridEvents.confirm(data,widget);
							}
						}]
					} ]
				}
			});

			widget.set("grid", grid);
		}
	};
	module.exports = instance;
});
